// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';



const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routerErrorEach: ({
		type,
		level,
		...args
	}) => {

		// #ifdef APP-PLUS
		if (type === 3) {
			router.$lockStatus = false;
			const pages = getCurrentPages();
			const currentPage = pages[pages.length - 1];
			if (level == 1 && args.uniActualData.from === 'backbutton') {
				if (currentPage.$page.meta.isQuit) {
					runtimeQuit();
				}
			}
		}
		// #endif
	},
	routes: [...ROUTES],
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	if (!uni.getStorageSync("accessToken")) {
		if (to.path !== '/pages/auth/login') {
			return next({
				path: '/pages/auth/login',
				NAVTYPE: 'push'
			});
		}
		next()
	} else {
		next()
	}
});
// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log('跳转结束')
})

export {
	router,
	RouterMount
}
